package com.example.textviewpractical;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void register(View view){
       EditText nameEdit = findViewById(R.id.name);
       EditText passwordEdit = findViewById(R.id.password);
       ProgressBar progressBar = findViewById(R.id.pro_bar);
        String name = nameEdit.getText().toString();
        String pwd = passwordEdit.getText().toString();
        if(name.equals("") || pwd.equals("")){
            Toast.makeText(this,"用户名或密码不能为空",Toast.LENGTH_SHORT).show();
        }else{
            progressBar.setVisibility(View.VISIBLE);
            new Thread(()->{
                for (int i = 1; i <= 100; i++) {
                    progressBar.setProgress(i);
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}